##
# Author: Samuel Abels <http://debain.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
##
from config         import c as cfg
from SpiffWarehouse import MultiBlob, Blob, Text, Xml

class Workflow(object):
    def __init__(self):
        self.blob = MultiBlob(summary = Text(''), content = Blob(''))


    @classmethod
    def from_blob(self, blob):
        workflow      = Workflow()
        workflow.blob = blob
        return workflow


    def get_id(self):
        return self.blob.id


    def get_version(self):
        return self.blob.revision


    def get_uri(self):
        return 'workflow:' + str(self.get_id())


    def _update(self):
        searchable = '\n'.join([self.get_name(),
                                self.get_summary(),
                                self.get_content()])
        self.blob.set_text(searchable.replace('\x00', ''))


    def set_deleted(self, deleted):
        self.blob.deleted = deleted


    def is_deleted(self):
        return self.blob.deleted


    def set_name(self, name):
        self.blob.name = 'workflow/' + name
        self._update()


    def get_name(self):
        return self.blob.name[len('workflow/'):]


    def set_summary(self, summary):
        self.blob.set('summary', Text(summary))
        self._update()


    def get_summary(self):
        return str(self.blob.get('summary'))


    def set_content(self, content):
        self.blob.set('content', Blob(content))
        self._update()


    def get_content(self):
        return self.blob.get('content').bin()


    def is_completed(self):
        return True # no actual states exist for now.
